<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Albums model
 *
 * @subpackage	Albums Module
 * @album	Modules
 * @author lethanhquang910@gmail.com
 */
class Albums_m extends CI_Model {

    /**
     * Get all album
     * @param type $arrParams
     * @return type 
     */
    public function get_all_album($arrParams = NULL, $limit = 20, $offset = 0) {
        
        $this->db->select('albums.*, category.title');
        $this->db->join('category', 'category.category_id = albums.category_id');

        $query = $this->db->get_where('albums', $arrParams, $limit, $offset);
        
        $result = array(
            'data' => $query->result_array(),
            'total' => $this->db->count_all('albums')
        );
        
        return $result;
    }
    
    /**
     * get album detail
     * @param type $id
     * @return type 
     */
    public function get_album_detail($id) {
        $result = $this->db->get_where('albums', array('album_id' => $id))->row_array();
        
        if($result){
            $this->db->query("UPDATE albums SET total_view = total_view + 1 WHERE album_id = " . $id);
        }
        
        return $result;
    }
    
    /**
     * get photos by albumID
     * @param type $id
     * @return type 
     */
    public function get_photos_by_album($id) {
        $query = $this->db->get_where('photos', array('album_id' => $id));
        
        return $query->result_array();
    }

}